<?php
	require_once ('config/connection.php');
	$data=simplexml_load_file("../assets/data/Data.xml");
       
     
       //INSERT VEHICLE MAKE DATA
    /* foreach($data->make->label as $make)
        {
            //    echo "INSERT INTO vehicle_make (make, active, created_by, create_date) VALUES('".$make."', 1, 2, NOW())<br/>";
            // mysql_query("INSERT INTO vehicle_make (make, active, created_by, create_date) VALUES('".$make."', 1, 2, NOW())") or die("MYSQL ERROR");  
            
           $make_name=$make->attributes()->dataField;
         // echo  $data->$make_name->item[1]->label;
           
          foreach($data->$make_name->item as $model)
           { 
             //echo  $model->label."<br/>";
                echo $query = "INSERT INTO vehicle_model (model_name, make_id, active, created_by, create_date) VALUES('".$model->label."', (SELECT make_id FROM vehicle_make WHERE make='".$make."'), 1, 2, NOW())";
               
              // mysql_query($query)or die("Mysql error".$query);
               //    echo $query."<br/>";
             
           }  
                   
        }*/
        
  /*  $result= mysql_query("SELECT category_name FROM asset_category");
    while($category=mysql_fetch_array($result))
    {
        $cat_name = $category["category_name"];
        if(isset($data->$cat_name))
        {
            //echo $cat_name.":-";
            echo $data->$cat_name->getName();
             if($data->$cat_name->getName()=="deliveryType")
             {
              foreach($data->$cat_name->label as $asset)
              {      
               
               
                     echo $asset."</br>";
                 // if($asset!="Have Title (Previous owner's name)"&&$asset!="Have Title (In my name)"&&$asset!="Title Lost (In my name)"&&$asset!="Title Lost (Previous owner's name)")
                //  {    
                    echo $query = "INSERT INTO assets (asset_name, asset_category, active, created_by, create_date) VALUES('".$asset."', (SELECT category_id FROM asset_category WHERE category_name='".$cat_name."'), 1, 2, NOW())";
                    
                   //  mysql_query($query) or die("MYSQL ERROR");  
                //  }   
                      
                  
           
              }
             } 
               //  echo "<br/>";
        }       
    } 
        
      
    /* foreach($data->sortCriteria->label as $asset)
     {    
         echo "UPDATE assets SET asset_datafield='".$asset->attributes()->dataField."' WHERE asset_name='".$asset."' AND asset_category=11";
         
        mysql_query("UPDATE assets SET asset_datafield='".$asset->attributes()->dataField."' WHERE asset_name='".$asset."' AND asset_category=5") or die("mysql error");     
     }*/        
    
  /* $vehicle_list = mysql_query("SELECT * FROM vehicle1");

   while ($vehicle= mysql_fetch_object($vehicle_list))
   {    
       $make_id = mysql_fetch_array(mysql_query("SELECT make_id FROM vehicle_make WHERE make='".$vehicle->make."'"));
       $make_id=$make_id["make_id"];
        $query = "UPDATE vehicle SET 
                  make=".$make_id.", 
                  model=(SELECT model_id FROM vehicle_model WHERE model_name='".$vehicle->model."' AND make_id=".$make_id."),
                  engine=(SELECT asset_id FROM assets WHERE asset_name='".$vehicle->engine."' AND asset_category=2),
                  transmission=(SELECT asset_id FROM assets WHERE asset_name='".$vehicle->transmission."' AND asset_category=3),
                  drivetrain_type=(SELECT asset_id FROM assets WHERE asset_name='".$vehicle->drivetrain_type."' AND asset_category=1),
                  ad_source=(SELECT asset_id FROM assets WHERE asset_name='".$vehicle->ad_source."' AND asset_category=9),
                  i_want_to=(SELECT asset_id FROM assets WHERE asset_name='".$vehicle->i_want_to."' AND asset_category=4),
                  contact_me=(SELECT asset_id FROM assets WHERE asset_name='".$vehicle->contact_me."' AND asset_category=5),
                  located_at=(SELECT asset_id FROM assets WHERE asset_name='".$vehicle->located_at."' AND asset_category=7),
                  paper_work=(SELECT asset_id FROM assets WHERE asset_name='".addslashes($vehicle->paper_work)."' AND asset_category=6),
                  delivery_option=(SELECT asset_id FROM assets WHERE asset_name='".$vehicle->delivery_option."' AND asset_category=8) WHERE vehicle_id=".$vehicle->vehicle_id."";
        mysql_query($query) or die("Error".$query);
        
        echo $query;
        echo "Vehicle #".$vehicle->vehicle_id."Updated <br/>";
   } */ 
?>